import pymysql

if __name__ == '__main__':
    try:
        # 连接数据库
        connc = pymysql.Connect(
            host="localhost",
            user="root",
            password="123456",
            port=3306,
            database="text_dba",
            charset="utf8"
        )
        # 获取游标
        cur=connc.cursor()
        # 执行sql语句
        sql="select * from customers"
        cur.execute(sql)
        # 获取查询结果
        result=cur.fetchall()
        print(result)
        # 关闭游标和连接
        cur.close()
        connc.close()
    except Exception as e:
        print(e)
